<?php

    header('Content-type:text/html; charset=utf-8');
    session_start();
    //$_filename=(basename($_SERVER['PHP_SELF'],'.php'));
    //判断是否勾选自动登录 是则把信息保存到session中
        if(empty($_SESSION['admin']) && !empty($_COOKIE['auto_login']) && !empty($_COOKIE['username']) && !empty($_COOKIE['password'])){
        $_SESSION['admin']['username']=$_COOKIE['username'];
        header('location:index.php?c=index&a=index&admin=1'); die;

    }
    //如果访问登录页面 则直接跳到首页
    if(!empty($_COOKIE['auto_login'])&&$a=='login'){
        header('location:index.php?c=index&a=index&admin=1'); die;
    }
    //判断用户是否登录
    if(empty($_SESSION['admin']) && $a!='login' &&$a!='code' && !empty($_GET['admin'])){
        echo '<script>alert("请登录");location.href="index.php?c=admin&a=login&admin=1";</script>'; die;
    }
    if(empty($_GET['admin'])){
        $l='home';
    }else{
        $l='admin';
    }

$_filename=VIEW_PATH.$l.'/'.$c.'/'.$a.'.tpl';
        //设置时区为亚洲上海
        date_default_timezone_set('Asia/shanghai');
        //数据库功能代码
        include_once 'my_db.php';
         $link=db_connect('cms');
        //翻页功能代码
        include_once 'pages.php';
        //引入缩略图
        include_once 'thumb.php';
        //文件上传代码
        include_once 'file_load.php';
        if(!empty($_GET['admin'])){
            //权限验证
            $rule['rule']= $c.'/'.$a;
            $power_id= getSelectOne('power',$rule)['id'];
            //print_r ($_SESSION);die;
            if($a=='login' || $a=='loginout' || $a=='index' || $a=='' ||$a=='code' ||$a=='kaoshi'){

                $_filename=VIEW_PATH.'admin/'.$c.'/'.$a.'.html';

            }else if(in_array($power_id,$_SESSION['power'])){
                //echo 1;die;
                $_filename=VIEW_PATH.'admin/'.$c.'/'.$a.'.html';

            }else{

                echo '<script>alert("无权限");history.go(-1);</script>';die;
            }
        }


        //smarty插件
        require_once(LIB_PATH . 'libs/Smarty.class.php');//加载smarty类文件

        $smarty = new Smarty();//实例化smarty类对象


        $smarty->template_dir = '';//模版(视图)路径

        $smarty->assign('filename',$_filename);

        $smarty->compile_dir  = VIEW_PATH.'templates_c/';//smarty编译文件路径

        $smarty->cache_dir    = VIEW_PATH.'cache/';//缓存目录路径
        //边界符修改
        $smarty->left_delimiter='<{';
        $smarty->right_delimiter='}>';
        //缓存
        $smarty->caching=2;
        $smarty->cache_lifetime=0;
